<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="教师" prop="name">
        <el-select v-model="queryParams.teacherId" placeholder="教师" clearable>
            <el-option v-for="dict in teacherList" :key="dict.teacherId" :label="dict.teacher.name" :value="dict.teacherId" />
          </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="teacherList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="教师名称" align="center" prop="name" />
      <el-table-column label="学科" align="center" prop="subjectName" />
      <el-table-column label="教师评分" align="center" prop="teacherScore" />
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="学科编号" align="center" prop="subjectId" />
      <el-table-column label="申请材料" align="center" prop="applicationFile" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.applicationFile" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_teacher_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:teacher:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleHireTeacher(scope.row)"
            v-hasPermi="['system:teacher:edit']" v-if="roleCode == 'parent'">聘请教师</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleApplicationSuccess(scope.row)"
            v-hasPermi="['system:teacher:edit']"
            v-if="roleCode == 'admin' && scope.row.status == 'ADMIN_APPLICATION'">申请通过</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleApplicationFail(scope.row)"
            v-hasPermi="['system:teacher:edit']"
            v-if="roleCode == 'admin' && scope.row.status == 'ADMIN_APPLICATION'">申请驳回</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:teacher:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />


  </div>
</template>

<script>
import { getMyCourseList } from "@/api/system/course";

export default {
  name: "Teacher",
  dicts: ['sys_teacher_status'],
  data() {
    return {
      openHire: false,
      familyList: [],
      roleCode: null,
      subjectList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 家教教师表格数据
      teacherList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        price: null,
        subjectId: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.roleCode = localStorage.getItem("roles")
    var teacherId = localStorage.getItem("teacherId")
    if(teacherId != null) {
      this.queryParams.teacherId = teacherId
    }
  },
  methods: {
    
    /** 查询家教教师列表 */
    getList() {
      this.loading = true;
      getMyCourseList(this.queryParams).then(response => {
        this.teacherList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openHire = false
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        price: null,
        subjectId: null,
        applicationFile: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    
  }
};
</script>
